/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
	"mysqlAdmin/lib/log"
	userAdmin "mysqlAdmin/lib/userAdm"

	"github.com/spf13/cobra"
)

// userCmd represents the user command
var userCmd = &cobra.Command{
	Use:   "user",
	Short: "mysql用户管理",
	Long:  `mysql用户管理`,
	Run: func(cmd *cobra.Command, args []string) {
		// fmt.Println("user called")
		doAction()
	},
}

var action string

func init() {
	rootCmd.AddCommand(userCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// userCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	// userCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
	// userCmd.Flags().StringP("action", "a", "add", "用户操作")
	userCmd.Flags().StringVarP(&action, "action", "a", "add", "用户操作")
}

func doAction() {
	log.Infof("action:%v", action)
	if action == "add" {
		userAdmin.Add()
	}

	if action == "del" {
		userAdmin.Del()
	}

}
